	package com.cainli.image;

import android.graphics.ColorFilter;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Drawable.Callback;

/**
 * 代理Drawable
 * 
 *
 */
public abstract class ProxyDrawable extends Drawable implements Callback
{
    /**
     * 当前使用的Drawable
     */
    protected Drawable mCurrDrawable;
    private boolean mMutated;
    
    public ProxyDrawable(Drawable proxy)
    {
        if(proxy == null)
        {
            throw new IllegalArgumentException("proxy drawable can't be null!");
        }
        mCurrDrawable = proxy;
        mCurrDrawable.setCallback(this);
    }

    @Override
    public int getChangingConfigurations()
    {
        return mCurrDrawable.getChangingConfigurations();
    }

    @Override
    public boolean getPadding(Rect padding)
    {
        return mCurrDrawable.getPadding(padding);
    }

    @Override
    public void setAlpha(int alpha)
    {
        mCurrDrawable.setAlpha(alpha);
    }

    @Override
    public void setDither(boolean dither)
    {
        mCurrDrawable.setDither(dither);
    }

    @Override
    public void setColorFilter(ColorFilter cf)
    {
        if (mCurrDrawable != null)
        {
            mCurrDrawable.setColorFilter(cf);
        }
    }

    @Override
    protected void onBoundsChange(Rect bounds)
    {
        if (mCurrDrawable != null)
        {
            mCurrDrawable.setBounds(bounds);
        }
    }

    @Override
    public boolean isStateful()
    {
        return mCurrDrawable.isStateful();
    }

    @Override
    protected boolean onStateChange(int[] state)
    {
        return mCurrDrawable.setState(state);
    }

    @Override
    protected boolean onLevelChange(int level)
    {
        return mCurrDrawable.setLevel(level);
    }

    @Override
    public int getIntrinsicWidth()
    {
        return mCurrDrawable.getIntrinsicWidth();
    }

    @Override
    public int getIntrinsicHeight()
    {
        return mCurrDrawable.getIntrinsicHeight();
    }

    @Override
    public int getMinimumWidth()
    {
        return mCurrDrawable.getMinimumWidth();
    }

    @Override
    public int getMinimumHeight()
    {
        return mCurrDrawable.getMinimumHeight();
    }

    @Override
    public int getOpacity()
    {
        return mCurrDrawable.getOpacity();
    }

    @Override
    public Drawable mutate()
    {
        if (!mMutated && super.mutate() == this)
        {
            mCurrDrawable.mutate();
            mMutated = true;
        }
        return this;
    }

    @Override
    public void invalidateDrawable(Drawable who)
    {
        this.invalidateSelf();
    }

    @Override
    public void scheduleDrawable(Drawable who, Runnable what, long when)
    {
        scheduleSelf(what, when);
    }

    @Override
    public void unscheduleDrawable(Drawable who, Runnable what)
    {
        unscheduleSelf(what);
    }

}
